import  {baseURL} from "./util.js"
// loading配置
function startLoading() {
  wx.showToast({title: '加载中', icon: 'loading', duration:3000});
}
// 停止loading配置
function stopLoading() {
  wx.hideToast()
}

export default function request(options) {
  startLoading();
  return new Promise((resolve, reject) => {
    wx.request({
      //这里使用到config.js的全局url地址
      url: baseURL + options.url,
      method: options.method || 'get',
      data: options.data || null,
      success: function (res) {
        resolve(res);
        stopLoading()
      },
      fail:function (res) {
        // fail调用接口失败
        wx.showToast({
          title: "网络错误",
          icon: "none",
          duration: 5000
        });
        reject({ error: '网络错误', code: 0 });
   
      },
    })
  })
  
}
